// pages/AA_wxjlview/AA_wxjlview.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:"",
    img1: '',
    img2: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  img: function (e) {
    var that = this
    wx.showActionSheet({
      itemList: ['相机', '相册'],
      itemColor: 'itemColor',
      success: (result) => {
        switch (result.tapIndex) {
          case 0:
            wx.chooseImage({
              count: 1,
              sourceType: ['camera'],
              complete: (res) => {
                if (e.currentTarget.id == 'i1') {
                  that.setData({ img1: res.tempFilePaths })
                } else {
                  that.setData({ img2: res.tempFilePaths })
                }

              },
            })
            break;
          case 1:
            wx.chooseImage({
              count: 1,
              sourceType: ['album'],
              complete: (res) => {
                if (e.currentTarget.id == 'i1') {
                  that.setData({ img1: res.tempFilePaths })
                } else {
                  that.setData({ img2: res.tempFilePaths })
                }
              },
            })
            break;
        }
      },
    })
  },
  changeimg: function (e) {
    console.log(e)
    var that = this
    wx.showActionSheet({
      itemList: ['重新上传', '预览图片', '删除'],
      itemColor: 'itemColor',
      success: (result) => {
        switch (result.tapIndex) {
          case 0:
            wx.chooseImage({
              count: 1,
              sourceType: ['album', 'camera'],
              complete: (res) => {
                if (e.currentTarget.id == 'ci1') {
                  that.setData({ img1: res.tempFilePaths })
                } else {
                  that.setData({ img2: res.tempFilePaths })
                }

              },
            })
            break;
          case 1:
            if (e.currentTarget.id == 'ci1') {
              wx.previewImage({
                current: '', // 当前显示图片的http链接
                urls: that.data.img1 // 需要预览的图片http链接列表
              })
            } else {
              wx.previewImage({
                current: '', // 当前显示图片的http链接
                urls: that.data.img2 // 需要预览的图片http链接列表
              })
            }
            break;
          case 2:
            if (e.currentTarget.id == 'ci1') {
              that.setData({ img1: '' })
            } else {
              that.setData({ img2: '' })
            }
            break;
        }
      },
    })
  },


  formSubmit:function(e){
    var that=this
    if(e.detail.value.name.length==0){
      wx.showToast({
        title: '维修人不能为空',
        icon:'none'
      })
    }else if(e.detail.value.des.length==0){
      wx.showToast({
        title: '修复描述不能为空',
        icon:'none'
      })
    }else{

    console.log(that.data.id)
    console.log(e.detail.value)
    wx.request({
      url: app.globalData.URL+'/dormitory_repair/update_repair_status',
      method:"POST",
      data:{
        repair_id:that.data.id,
        user_id:wx.getStorageSync('userid'),
        password:wx.getStorageSync('password'),
        repair_time:'',
        repair_des:e.detail.value.des,
        repair_people:e.detail.value.name
      },
      success:function(res){
        console.log(res.data)
        wx.showToast({
          title: '修复成功',
          icon:'none'
        })
        setTimeout(function(){
          wx.switchTab({
            url: '/pages/index/index'
          })
        },3000)
      }
    })
  }
  },
  onLoad: function (options) {
    var that=this
    console.log(options.id)
    that.setData({id:options.id})
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})